/**
 *
 */
package org.suren.littlebird.views.drop;

import org.eclipse.core.internal.resources.File;
import org.eclipse.core.internal.resources.Folder;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.suren.littlebird.sync.FileSync;
import org.suren.littlebird.views.InstallBundleDialog;

/**
 * @author suren
 *
 */
public class BundleDropTarget extends DropTargetAdapter
{
	private InstallBundleDialog dialog;

	private FileSync fileSync = new FileSync();

	/**
	 * @param dialog
	 */
	public BundleDropTarget(InstallBundleDialog dialog)
	{
		this.dialog = dialog;
	}

	@Override
	public void drop(DropTargetEvent event)
	{
		super.drop(event);
		Object obj = ((TreeSelection)event.data).getFirstElement();
		System.out.println(obj.getClass());

		if(obj instanceof IProject)
		{
			IProject project = (IProject) obj;
			System.out.println(project.getLocation());
		}
		else if(obj instanceof Folder)
		{
			Folder folder = (Folder) obj;
			System.out.println(folder.getFullPath());
		}
		else if(obj instanceof File)
		{
			File file = (File) obj;
			System.out.println(file.getFullPath());
			System.out.println(file.getProject().getLocation());
			System.out.println(file.getLocation().makeAbsolute().toFile().getAbsolutePath());

			bundleHandler(file);
		}
	}

	/**
	 * @param file
	 */
	private void bundleHandler(File file)
	{
		boolean scpResult = fileSync.bundleHandler(dialog, file);

		callBack(scpResult, fileSync.getDstFile());
	}

	protected void callBack(boolean scpResult, String dstFile)
	{
	}
}
